/**
 * infer使用
 *
 */

interface Customer {
  custname: string;
  bugmoney: number;
}

type custFuncType = (cust: Customer) => string; // 函数类型 // ? (cust: Customer,str: string) => string; // 两个参数 不符合,T extends (params: infer P) => any ? P : T;所以得到的结果是T
//! (1)infer出现在 extends 条件语句后的函数类型的参数类型位置上
type inferType<T> = T extends (params: infer P) => any ? P : T;
// 等价 type inferType<custFuncType> = (cust:Cuntomer) => string extends (params:infer P)=>any?P:T

type inferResultType = inferType<custFuncType>;

// console.log("inferResultType", typeof inferResultType);



//! (2)现在extends条件语句后的函数类型的返回值类型上
// 使用infer去替换一种泛型
type inferType2<T> = T extends (params:  any) =>infer P ?  P : T;

type inferResultType2 = inferType2<custFuncType>;




//! 会出现在类型的泛型具体化类型上
class Subject {
  constructor(public subid: number, public subname: string) {
  }
}
let chineseSubject = new Subject(100, "语文")
let mathSubject = new Subject(101, "数学")
let englishSubject = new Subject(101, "英语")

let setZhangSanSubject = new Set<Subject>([chineseSubject, mathSubject, englishSubject]);
type ss = typeof setZhangSanSubject
type ElementOf0<T> = T extends Set<infer E> ? E : never;// 等待外部进行替换

let result: ElementOf0<typeof setZhangSanSubject>


export {};
